package com.szrt.javaweb;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


/**
 * 要想让Servlet被Servlet容器承认要在web.xml中做2件事
 * 	2.1:注册Servlet
 * 	2.2:映射Servlet
 * @author Administrator
 *
 */


public class HelloSessionServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
	
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		
		
		HttpSession session = request.getSession();
		
		//自家的保险柜放了1600
		request.setAttribute("moneySelf", 1600);
		
		//放在银行6000
		session.setAttribute("bank", 6000);
		
		String javaSessionId =session.getId();
		System.out.println(javaSessionId);
		request.setAttribute("javaSessionId", javaSessionId);
		
		//请求转发 相当于自己带保险柜去上海
		request.getRequestDispatcher("sh.jsp").forward(request, response);
		
		//重定向  相当于自己裸奔过去的
		//response.sendRedirect("sh.jsp");
		
		
		
		
		
	}

}
